﻿#region Copyright & licence

// This file is part of Refix.
// 
// Refix is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
// 
// Refix is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
// 
// You should have received a copy of the GNU Lesser General Public
// License along with Refix.  If not, see <http://www.gnu.org/licenses/>.
// 
// Copyright (C) 2010-11 David Musgrove and others.

#endregion

using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Reflection;
using System.Text;

using NUnit.Framework;

using Refix.Core.Commands;

namespace Refix.Core.Tests.Commands
{
    [TestFixture]
    public class UnregisterTest : TestSolutionFolderTest
    {
        [Test]
        public void Help_Shows_Appropriate_Text()
        {
            var builder = new StringBuilder();
            OutputWriter.Writer = new StringWriter(builder);
            var queue = new Queue<string>();
            queue.Enqueue("help");
            queue.Enqueue("unreg");
            new CommandWithOptions(queue).Command.Execute();
            StringAssert.Contains(": rfx unreg ", builder.ToString(), "Register help text didn't include short form.");
            StringAssert.Contains(": rfx unregister ", builder.ToString(), "Register help text didn't include long form.");
        }

        [Test]
        public void Unregister_Errors_If_No_Matches()
        {
            var builder = new StringBuilder();
            OutputWriter.Writer = new StringWriter(builder);
            OutputWriter.Verbository = OutputVerbosity.Quiet;
            Directory.SetCurrentDirectory(SolutionRootDirectory.FullName);

            Command unregister = new CommandWithOptions(new[] { "unreg", "-f", "No.Such.dll", "0.1" }).Command;

            Assert.False(unregister.Execute(), "Unregister did not return false with no file matches.");
            Assert.IsNotEmpty(builder.ToString(), "Unregister did not produce output with no file matches.");
        }

        [Test]
        public void Unregister_Errors_With_Wrong_Parameter_Count()
        {
            var builder = new StringBuilder();
            OutputWriter.Writer = new StringWriter(builder);
            OutputWriter.Verbository = OutputVerbosity.Quiet;
            Directory.SetCurrentDirectory(SolutionRootDirectory.FullName);

            Command unregister = new CommandWithOptions(new[] { "unreg", "Refix.Test.A" }).Command;

            Assert.False(unregister.Validate(), "Unregister did not return false with wrong parameter count.");
            Assert.IsNotEmpty(builder.ToString(), "Unregister did not produce output with wrong parameter count.");
        }
    }
}